//
//  LWRegisterTwoCtrl.m
//  laowu
//
//  Created by 尹桥印 on 15/5/5.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "LWRegisterTwoCtrl.h"
#import "CustomSpannerView.h"


#import "LWRegisterMGCtrl.h"//工友
#import "LWRegisterBCtrl.h"//班组长
#import "LWRegisterZCtrl.h"//质检员、施工员、业务员、业务经理、项目经理 注册页面
#import "LWRegisterOCtrol.h"//公司


@interface LWRegisterTwoCtrl ()<CustomSpannerViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UIView *jobTypeBtn;
@property (weak, nonatomic) IBOutlet UILabel *jobTypeLabel;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UITextField *pwdenterField;
@property (weak, nonatomic) IBOutlet UIButton *enterBtn;

@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UIView *view3;
@property (weak, nonatomic) IBOutlet UIView *view4;

@property (nonatomic,strong)NSMutableDictionary *param;

@end

@implementation LWRegisterTwoCtrl

-(instancetype)initWithPhone:(NSString *)phone{
    if (self=[super init]) {
        self.param = [NSMutableDictionary dictionary];
        [self.param setObject:phone forKey:@"user_name"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"注册"];
    [self.enterBtn setBackgroundColor:THEME_COLOR];
    [self.view1 setCornerRadius:5 borderWidth:1 borderColor:HEXColor(@"dfdfdf")];
    [self.view2 setCornerRadius:5 borderWidth:1 borderColor:HEXColor(@"dfdfdf")];
    [self.view3 setCornerRadius:5 borderWidth:1 borderColor:HEXColor(@"dfdfdf")];
    [self.view4 setCornerRadius:5 borderWidth:1 borderColor:HEXColor(@"dfdfdf")];
}

- (IBAction)workStatusBtnClick:(id)sender {
    UIButton *btn = sender;
    NSArray *stringArray = STRING_ARRAY_JIAOSE_STATUS;
    CustomSpannerView *spannerView = [[CustomSpannerView alloc] initWithStringArray:stringArray bearingView:btn];
    [spannerView setDelegate:self];
    [spannerView show];
}

-(void)customSpannerItemClick:(NSString *)title index:(NSInteger)index bearingView:(UIView *)bearingView{
    [self.jobTypeLabel setText:title];
}

- (IBAction)enterBtnClick:(id)sender {
    if (ISBLANK(self.nameField.text) || ISBLANK(self.pwdField.text) || ISBLANK(self.pwdenterField.text)) {
        [DialogUtils showTipsWithView:nil String:@"请把数据输入完整！"];
        return;
    }
    
    if (![self.pwdField.text isEqualToString:self.pwdenterField.text]) {
        [DialogUtils showTipsWithView:nil String:@"两次密码输入不一致"];
        return;
    }
    
    
    NSString *jobType = self.jobTypeLabel.text;
    
    UIViewController *ctrl = [[LWRegisterMGCtrl alloc] initWithDictionary:self.param];
    
    [self.param setObject:self.nameField.text forKey:@"attr_p_realname"];
    [self.param setObject:self.pwdField.text forKey:@"password"];
    
    if ([jobType isEqualToString:@"工友"]) {
        ctrl = [[LWRegisterMGCtrl alloc] initWithDictionary:self.param];
    }else if ([jobType isEqualToString:@"班(组)长"]){
        ctrl = [[LWRegisterBCtrl alloc] initWithDictionary:self.param];
    }else if ([jobType isEqualToString:@"质检员"] || [jobType isEqualToString:@"施工员"] || [jobType isEqualToString:@"业务员"] || [jobType isEqualToString:@"业务经理"] || [jobType isEqualToString:@"项目经理"]){
        
        /*
         
         4	施工员
         5	项目经理
         6	质检员
         7	业务员
         8	业务经理
         */
        
        NSString *groupId = @"4";
        
        if ([jobType isEqualToString:@"质检员"]) {
            groupId = @"6";
        }else if([jobType isEqualToString:@"施工员"]){
            groupId = @"4";
        }else if([jobType isEqualToString:@"业务员"]){
            groupId = @"7";
        }else if ([jobType isEqualToString:@"业务经理"]){
            groupId = @"8";
        }else{
            groupId = @"5";
        }
        [self.param setObject:groupId forKey:@"group_id"];
        ctrl = [[LWRegisterZCtrl alloc] initWithDictionary:self.param];
    }else if([jobType isEqualToString:@"劳务公司"]){
        [self.param setObject:@"11" forKey:@"group_id"];
        ctrl = [[LWRegisterOCtrol alloc] initWithDictionary:self.param];
    }
    [self.navigationController pushViewController:ctrl animated:YES];
}


- (IBAction)tap:(id)sender {
    [self.view endEditing:YES];
}


@end
